package com.example.demo.dynamicProxy;

import java.lang.reflect.Proxy;

/**
 * 动态代理
 */
public class DynamicProxyTest {

    public static void main(String[] args) throws Exception {
        LogInterception logInterception = new LogInterception();
        PermissionInterception permissionInterception = new PermissionInterception();
//        permissionInterception.setUserPermission("admin");
        permissionInterception.setUserPermission("admin");
        UserService target = new UserServiceImpl();
        UserProxy userProxy = new UserProxy(logInterception, permissionInterception, target);
        /** 生成代理类 */
        UserService proxy = (UserService) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), userProxy);
        proxy.toEat();
        proxy.toSleep();
        proxy.toShopping();

    }

}
